package com.ccsoft.annoreflect.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

/**
 * @author chanchaw
 * @create 2022-09-23 15:37
 */
public class DBUtils {
    private volatile static Connection connection;

    public static Connection getConnection(){
        Properties props = new Properties();
        props.put("remarksReporting","true");//获取数据库备注信息
        props.put("user","root");
        props.put("password","chanchaw");

        if(connection != null) return connection;

        synchronized (DBUtils.class){
            if(connection != null) return connection;

            try {
                Class.forName("com.mysql.jdbc.Driver");
                String url = "jdbc:mysql://localhost:3306/pademisaccount?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true";
                connection = DriverManager.getConnection(url,props);
            } catch (ClassNotFoundException e) {
                throw new RuntimeException(e);
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }

        return connection;
    }
}
